package cn.tedu.mall.search.controller;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.pojo.search.entity.SpuForElastic;
import cn.tedu.mall.search.service.ISearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/search")
@Api(tags = "搜索模块")
public class SearchController {
    @Autowired
    private ISearchService searchService;

    //  主要功能为实现搜索,这种功能的控制器可不写任何路劲
    //      @GetMapping表示当前路径为localhost:10008/search
    @GetMapping
    @ApiOperation("根据关键字查询es中的信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "搜索关键字",name = "keyword",dataType = "string",required = true),
            @ApiImplicitParam(value = "页码",name = "page",type = "int",required = true),
            @ApiImplicitParam(value = "每页条数",name = "pageSize",type = "int",required = true)
    })
    public JsonResult<JsonPage<SpuForElastic>> searchByKeyword(String  keyword,
                                                               @RequestParam(value = "page",defaultValue = "1")Integer page,
                                                               @RequestParam(value = "pageSize",defaultValue = "4")Integer pageSize){
        JsonPage<SpuForElastic> list= searchService.search(keyword, page, pageSize);
        return JsonResult.ok(list);
    }
}
